import { datePickerItem } from './datePickerProperty';
import { inputItem } from './inputProperty';
import { publicItem } from './publicProperty';
import { selectItem } from './selectProperty';
import { treeSelectItem } from './treeSelectProperty';

/**
 * 属性集合
 */
let propertyGather = {
  input: inputItem,
  select: selectItem,
  'date-picker': datePickerItem,
  'tree-select': [...treeSelectItem, ...selectItem]
};

let opAllItems = mergeAndDeduplicateArrays(inputItem, selectItem, datePickerItem, publicItem);

function mergeAndDeduplicateArrays(...arrays: any[]) {
  const result: any[] = [];
  const propSet = new Set<string>();

  for (const array of arrays) {
    for (const item of array) {
      if (!propSet.has(item.prop)) {
        result.push(item);
        propSet.add(item.prop);
      }
    }
  }

  return result;
}

/** 将对应类型添加公共属性过来 */
function setPropertyGather() {
  Object.keys(propertyGather).forEach(key => {
    const list = mergeAndDeduplicateArrays(propertyGather[key], publicItem);
    arrSortItemsByName(list, 'sort');
    propertyGather[key] = list;
  });
}

setPropertyGather();

export { propertyGather, mergeAndDeduplicateArrays, opAllItems };
